﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using jmetal.core;
using jmetal.encodings.solutionType;

namespace jmetal.problems
{
  public class Schaffer : Problem
  {
    public Schaffer (String solutionType)
    {
      numberOfVariables_ = 1;
      numberOfObjectives_ = 2;
      numberOfConstraints_ = 0;
      problemName_ = "Schaffer";
      
      lowerLimit_ = new double[numberOfVariables_];
      upperLimit_ = new double[numberOfVariables_];
      for (int i = 0; i < numberOfVariables_; i++)
      {
        lowerLimit_[i] = -100000;
        upperLimit_[i] = 100000;
      }

      if (solutionType == "Real")
        solutionType_ = new RealSolutionType (this);
      
    }

    public override void evaluate (Solution solution)
    {
      // <pex>
      if (solution == (Solution)null)
        throw new ArgumentNullException("solution");
      // </pex>
      Variable[] x = solution.variable_;
      
      double[] f = new double[numberOfObjectives_];
      f[0] = x[0].value_ * x[0].value_;
      
      f[1] = (x[0].value_ - 2.0) * (x[0].value_ - 2.0);
      
      solution.objective_[0] = f[0];
      solution.objective_[1] = f[1];
    }
    // evaluate
  }
}
